package com.njts.servlet;
import com.njts.bean.User;
import com.njts.dao.UseDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    UseDao useDao=new UseDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String password=req.getParameter("password");
        System.out.println(name+password);
        User user = useDao.login(name, password);
        PrintWriter writer = resp.getWriter();
        if(user!=null&&user.getType()==3){
            writer.write("200");
        }else{
            writer.write("404");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.getRequestDispatcher("/view/login.jsp").forward(req,resp);
    }
}
